﻿using System;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.IO;
using DayZAntiHax;
using System.Reflection;

namespace DayZAntiHax
{
    public partial class Program
    {
        public Program()
        {
        }

        static void setConsole()
        {
            Assembly assem = Assembly.GetEntryAssembly();
            AssemblyName assemName = assem.GetName();
            Version ver = assemName.Version;

            Console.CursorVisible = false;
            //System.Console.SetWindowPosition(0, 0);   // sets window position to upper left
            System.Console.SetBufferSize(80, 40);   // make sure buffer is bigger than window
            System.Console.SetWindowSize(80, 40);   //set window size to almost full screen 
            Console.Title = "DayZ AntiHax v " + ver.ToString();
            //System.Console.ResetColor(); //resets fore and background colors to default
        }  // End  setConsoleSize()

        static void progressBar(int progress, int total)
        {
            int xcol;
            int xrow;
            ConsoleColor xforecolor = Console.ForegroundColor;
            ConsoleColor xbackcolor = Console.BackgroundColor;
            xcol = Console.CursorLeft;
            xrow = Console.CursorTop;
            int width = Console.WindowWidth - 1;
            int NumberBars = 20 * (progress / total);
            
            Console.CursorLeft = Console.LargestWindowWidth - 23;
            Console.CursorTop = Console.LargestWindowHeight -1;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Write("[");
            for (int i = 0; i < NumberBars; i++)
            {
                Console.Write("\u2590");
            }
            Console.Write("]");
            Console.CursorTop = xrow;
            Console.CursorLeft = xcol;
            Console.ForegroundColor = xforecolor;
            Console.BackgroundColor = xbackcolor;
        }

        static void Main(string[] args)
        {
            Process Process1 = new Process();
            
            if (Process1.Initialize())
            {
                
                setConsole();
                Console.WriteLine("Parsing frequency set to {0} second(s)", Process1.ParsingFrequency);
                Console.WriteLine("Flood checking {0}", Process1.ShouldCheckForFlooding ? "enabled" : "disabled");

                Console.WriteLine(String.Empty);
                Console.WriteLine("Initialization complete. Waiting to execute first pass...");
                Console.WriteLine(String.Empty);

                //using (new Timer(Process1.Execute, null, TimeSpan.FromSeconds(Process1.ParsingFrequency), TimeSpan.FromSeconds(Process1.ParsingFrequency)))
                using (new Timer(Process1.Execute, null, TimeSpan.FromSeconds(Process1.ParsingFrequency), TimeSpan.FromSeconds(Process1.ParsingFrequency)))
                {
                    while (true)
                    {
                        if (Console.ReadLine() == "quit")
                        {
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }
    }
}